#-------------------------------------------------------------------------------
# Name:        win32
# Purpose:
#
# Author:      SUPER_紫电  QQ:911344755
#
# Created:     21/08/2022
# Copyright:   (c) SUPER_紫电 2022 All rights reserved.
# Licence:     <Modified BSD License>
#-------------------------------------------------------------------------------

from ctypes import windll, wintypes

FARPROC = wintypes.LPDWORD

INVALID_HANDLE_VALUE = wintypes.HANDLE(-1).value
LPSECURITY_ATTRIBUTES = wintypes.LPVOID
LPOVERLAPPED = wintypes.LPVOID

CloseHandle = windll.kernel32.CloseHandle
CloseHandle.restype = wintypes.BOOL
CloseHandle.argtypes = [wintypes.HANDLE]   #HANDLE hObject

CreateFile = windll.kernel32.CreateFileW
CreateFile.restype = wintypes.HANDLE
CreateFile.argtypes = [
    wintypes.LPWSTR,       # _In_          LPCTSTR lpFileName
    wintypes.DWORD,        # _In_          DWORD dwDesiredAccess
    wintypes.DWORD,        # _In_          DWORD dwShareMode
    LPSECURITY_ATTRIBUTES, # _In_opt_      LPSECURITY_ATTRIBUTES lpSecurityAttributes
    wintypes.DWORD,        # _In_          DWORD dwCreationDisposition
    wintypes.DWORD,        # _In_          DWORD dwFlagsAndAttributes
    wintypes.HANDLE]       # _In_opt_      HANDLE hTemplateFile

DeviceIoControl = windll.kernel32.DeviceIoControl
DeviceIoControl.restype = wintypes.BOOL
DeviceIoControl.argtypes = [
    wintypes.HANDLE,   #HANDLE          hDevice
    wintypes.DWORD,    #DWORD           dwIoControlCode
    wintypes.LPVOID,   #LPVOID          lpInBuffer
    wintypes.DWORD,    #DWORD           nInBufferSize
    wintypes.LPVOID,   #LPVOID          lpOutBuffer
    wintypes.DWORD,    #DWORD           nOutBufferSize
    wintypes.LPDWORD,  #LPDWORD         lpBytesReturned
    LPOVERLAPPED]      #LPOVERLAPPED    lpOverlapped

LoadLibrary = windll.kernel32.LoadLibraryW
LoadLibrary.restype = wintypes.HMODULE
LoadLibrary.argtype = [
    wintypes.LPCWSTR,    # _In_ LPCTSTR lpFileName
]

FreeLibrary = windll.kernel32.FreeLibrary
FreeLibrary.restype = wintypes.BOOL
FreeLibrary.argtypes = [
    wintypes.HMODULE,    # HMODULE hLibModule
]

GetProcAddress = windll.kernel32.GetProcAddress
GetProcAddress.restype = FARPROC
GetProcAddress.argtypes = [
    wintypes.HMODULE,    # HMODULE hLibModule
]
